/* Copyright (C) 2008  Romolo Camplani, Marco Fortunato, Marco Marelli, Guido Rota, Fabio A. Schreiber et al.
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; either version 2
 * of the License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
 */
package org.dei.perla.parser.expressions;

public class NodeLogicalObjectAttribute extends Node {
	
	class ConstantAttribute extends Constant {
		private String identifier;
		private String qualifier;
		
		public ConstantAttribute(String identifier, String qualifier) {
			this.qualifier = qualifier;
			this.identifier = identifier;
		}
		
		public ConstantAttribute(String identifier) {
			this.qualifier = null;
			this.identifier = identifier;
		}
		
		/*
		public ConstantLogic exist(ConstantString parConst) throws ConstantCastException {
			if (parConst.getClass() == ConstantString.class) {
				if (attributeValue.equals(parConst.getValueString()))
					return new ConstantLogic(LogicValue.TRUE);
				else
					return new ConstantLogic(LogicValue.FALSE);
			}
			else
				throw new ConstantCastException("Incompatible Constant type for the operation.");
		}
		*/
		public String toString() {
			if(qualifier == null)
			{
				return identifier + "("+pValue.toString()+")";
			}
			else
			{
				return identifier + "." + qualifier + "("+pValue.toString()+")";
			}
		}
	}
	
	private ConstantAttribute attValue;
	
	/**
	 * Rappresenta il vero valore assunto dal campo oggetto logico
	 */
	private Constant pValue;
	
	/**
	 * Restituisce il vero valore assunto dal campo oggetto logico 
	 * @return Constant che rappresenta il valore
	 */
	public Constant getLogicalObjectValue() {
		
		return this.pValue;
		
	}
	
	/**
	 * Imposta il vero valore assunto dal campo oggetto logico
	 * @param parValue valore da impostare
	 */
	public void setLogicalObjectValue(Constant parValue) {
		
		this.pValue = parValue;
	}
	
	public String getLogicalObjectAttributeName() {
		
		return this.attValue.identifier;
	}
	
	
	public NodeLogicalObjectAttribute(String identifier, String qualifier) {
		this.attValue = new ConstantAttribute(identifier, qualifier);
	}
	
	public NodeLogicalObjectAttribute(String identifier) {
		this.attValue = new ConstantAttribute(identifier);
	}
	
	//il vecchio getResult restituiva this.attValue
	public Constant getResult() {
		return this.pValue;
	}
	
	public String toString() {
		return this.attValue.toString();
	}

}
